package com.woniu.account.controller;


import com.woniu.account.model.TRole;
import com.woniu.account.service.TRoleService;
import com.woniu.core.util.PageInfo;
import com.woniu.core.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴彦祖
 * @since 2024年04月02日
 */
@RestController
@RequestMapping("/tRole")
@Api(tags = "角色表相关接口")
public class TRoleController {

    @Resource
    private TRoleService tRoleService;
    @ApiOperation("角色列表查询")
//    @RequiredRole(role = {"超级管理员","普通管理员","团队负责人"})
    @GetMapping("/list")
    public Result roleList(Integer pageNum, Integer pageSize)throws Exception{
        PageInfo<TRole> search = tRoleService.search(pageNum,pageSize);
        return Result.getResult(PageInfo.class).setMsg("查询成功").setData(search);
    }

    @PostMapping("/insert")
    @ApiOperation("角色新增")
//    @RequiredRole(role = {"超级管理员","普通管理员","团队负责人"})
    public Result insert(String roleName) throws Exception{
        TRole tRole=tRoleService.insert(roleName);
        return  Result.getResult(TRole.class).setMsg("新增角色成功").setData(tRole);
    }

    @GetMapping("/delById")
    @ApiOperation("角色删除")
//    @RequiredRole(role = {"超级管理员","普通管理员","团队负责人"})
    public Result delById(Integer roleId) throws Exception{
        TRole tRole=tRoleService.delById(roleId);
        return Result.getResult(TRole.class).setMsg("删除角色成功").setData(tRole);
    }

    @GetMapping("/update")
    @ApiOperation("角色修改")
//    @RequiredRole(role = {"超级管理员","普通管理员","团队负责人"})
    public Result updateName(Integer roleId,String roleName) throws Exception{
        TRole tRole=tRoleService.updateName(roleId,roleName);
        return  Result.getResult(TRole.class).setMsg("修改角色名称成功").setData(tRole);
    }

    @GetMapping("/findAllRole")
    @ApiOperation("分配角色用")
//    @RequiredRole(role = {"超级管理员","普通管理员","团队负责人"})
    public Result findAllRole()throws Exception{
        List<TRole> role = tRoleService.findAllRole();
        return  Result.getListResult(TRole.class).setMsg("查询成功").setData(role);
    }

}

